use crate::entities::tasks;
use crate::routes::AppState;
use axum::extract::State;
use axum::Json;
use sea_orm::ActiveValue::Set;
use sea_orm::{
    ActiveModelTrait, ConnectionTrait, Database, DbBackend, DbErr, RuntimeErr, Statement,
};
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct RequestTask {
    title: String,
    priority: Option<String>,
    description: Option<String>,
}

pub async fn create_task(State(app_state): State<AppState>, Json(request_task): Json<RequestTask>) {
    let new_task = tasks::ActiveModel {
        priority: Set(request_task.priority),
        title: Set(request_task.title),
        description: Set(request_task.description),
        // user_id: todo!(),
        ..Default::default()
    };

    let result = new_task.save(&app_state.database).await.unwrap();
    // Ok(())
    dbg!(result);
}
